package com.zijing2333.servicerunner;

import android.os.Parcel;
import android.os.Parcelable;

public enum JSStatus implements Parcelable {

    CODE_NOT_DOWNLOADED(0),
    CODE_DOWNLOADING(1),
    CODE_DOWNLOADED(2),
    CODE_DOWNLOAD_FAILED(3),
    RUNNING(4),
    RUN_FAILED(5),
    RUN_COMPLETED(6);

    private final int value;

    JSStatus(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    @Override
    public String toString() {
        return "JSStatus{" +
                "value=" + value +
                '}';
    }

    public static JSStatus fromValue(int value) {
        for (JSStatus status : values()) {
            if (status.getValue() == value) {
                return status;
            }
        }
        return null;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.value);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<JSStatus> CREATOR = new Creator<JSStatus>() {
        public JSStatus createFromParcel(Parcel in) {
            return JSStatus.fromValue(in.readInt());
        }

        public JSStatus[] newArray(int size) {
            return new JSStatus[size];
        }
    };
}
